home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / EnterAct 3.5 / Drag_on Modules / hAWK programs / $Chain < prev    next >
Encoding:
Text File  |  1991-11-24  |  2.5 KB  |  66 lines  |  [TEXT/KEEN]

  1. #$Chain: call a bunch of little hAWK programs to repeatedly
  2. #filter and massage some text into the required shape. Rather
  3. #like piping. Any program which requires no libraries or
  4. #variables and sends its output to stdout is callable here.
  5. #Programs are executed from left to right (in the order typed in).
  6. #For example, entering
  7. #     notIndented firstField
  8. #will execute the program "notIndented" followed by 
  9. #the program "firstField" - stripping away all lines that
  10. #are indented, then trimming down to just the first field
  11. #on each line (use for example on the results of $XRef
  12. #to generate a bare list of names with no types or references).
  13.  
  14. #Usage:
  15. #There are two practical ways to provide input to this program; either
  16. #take input from "Front text selection" or "All of front text", or
  17. #set input to the specific file "$tempStdOut" -- the former is
  18. #more flexible, the latter means you don't have to bring any specific
  19. #file to the front before running this program.
  20. #Run, and when the dialog appears type in the names of the programs
  21. #you wish to be run on the text in tempStdOut (the first name you type
  22. #is the first program run). The final result will be in stdout, and will
  23. #be shown to you if you leave "Show stdout" selected.
  24.  
  25. #Ideally the little programs that this "dispatcher" calls should
  26. #free up memory when possible, since the "hAWK" call does not (yet)
  27. #do so automatically. See for example "asort".
  28.  
  29. #Little programs supplied: asort, nsort, dsort, rasort, rnsort, rdsort,
  30. #reverse, notIndented, firstField, secondField, thirdField, numberLines.
  31.  
  32. BEGIN {
  33.         if ((answer = prompt("Enter any of asort, nsort, dsort, rasort, rnsort, rdsort, reverse, notIndented, firstField, secondField, thirdField, numberLines -- exec order is left to right.")) != "")
  34.             {
  35.             n = split(answer, progs)
  36.             for (i = 1; i <= n; ++i)
  37.                 {
  38.                 #Note since "hAWK" is being repeatedly called, some care
  39.                 #must be taken to ensure that the array of arguments passed
  40.                 #along contains no spurious entries.
  41.                 if (notFirst == 1)
  42.                     {
  43.                     for (w in argv)
  44.                         delete argv[w];
  45.                     x = 0;
  46.                     }
  47.                 progFile = STDPATH "Drag_on Modules:hAWK programs:" progs[i]
  48.                 argv[x++] = "hAWK"
  49.                 argv[x++] = "-f" progFile
  50.                 argv[x++] = "--"
  51.                 #Input for the first program is whatever was supplied to
  52.                 #this program; for subsequent programs, the appropriate
  53.                 #input is in "$tempStdOut".
  54.                 if (notFirst != 1)
  55.                     {
  56.                     for (j = 1; j < ARGC; ++j)
  57.                         argv[x++] = ARGV[j]
  58.                     }
  59.                 else
  60.                     argv[x++] = STDPATH "$tempStdOut"
  61.                 notFirst = 1;
  62.                 hAWK(argv)
  63.                 }
  64.             }
  65.         }
  66.